package demo05_Quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import java.util.Date;

/**
 * @author liujun
 * @version 1.0
 * @date 2020/10/26
 * @author—Email liujunfirst@outlook.com
 * @blogURL https://blog.csdn.net/ljfirst
 * @description
 */
public class QuartzDemo {

    public static void main(String[] args) throws Exception {
        //1.调度器 scheduler
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        //2.触发器 触发任务执行
        Trigger trigger = TriggerBuilder
                .newTrigger()
                .withIdentity("myGroup1", "myTrigger1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(5)
                        .repeatForever()
                )
                .startNow()
                .build();
        //3.工作对象  jobDetail
        JobDetail jobDetail = JobBuilder.newJob(myjob.class)
                .withIdentity("myJob", "myGroup")
                .build();
        //4.注册任务和触发器
        Date date = scheduler.scheduleJob(jobDetail, trigger);
        //5.开启任务
        scheduler.start();
    }
}

